<?php

namespace App\Enums;

use MyCLabs\Enum\Enum;


final class OrderEnum extends Enum
{
    public const WechatPay = 'wechat';
    public const Alipay = 'alipay';
    public const Balance = 'balance';

    /**
     * 商户已创建服务订单
     */
    public const ORDER_CREATED = 'CREATED';
    /**
     * 服务订单进行中
     */
    public const ORDER_DOING = 'DOING';
    /**
     * 服务订单完成
     */
    public const ORDER_DONE = 'DONE';
    /**
     * 商户取消服务订单
     */
    public const ORDER_REVOKED = 'REVOKED';
    /**
     * 服务订单已失效
     */
    public const ORDER_EXPIRED = 'EXPIRED';
    /**
     * 用户已确认
     */
    public const ORDER_USER_CONFIRM = 'USER_CONFIRM';
    /**
     * 商户完结
     */
    public const ORDER_MCH_COMPLETE = 'MCH_COMPLETE';
    public const JSAPI = 'JSAPI';

    public static function getPaymentType()
    {
        return [
            self::WechatPay,
            self::Alipay,
            self::Balance
        ];
    }

    public static function getOrderStateDesc($value): string
    {
        $desc = "";

        switch ($value){
            case self::ORDER_CREATED:
                $desc = '已创建';
            break;
            case self::ORDER_DOING:
                $desc = '进行中';
            break;
            case self::ORDER_DONE:
                $desc = '已完成';
            break;
            case self::ORDER_REVOKED:
                $desc = '已取消';
            break;
            case self::ORDER_EXPIRED:
                $desc = '已过期';
            break;
        }

        return $desc;
    }

    public static function getOrderStateView($value): string
    {
        $desc = "";

        switch ($value){
            case self::ORDER_CREATED:
                $desc = '<text class="text-default">已创建</text>';
                break;
            case self::ORDER_DOING:
                $desc = '<text class="text-info">进行中</text>';
                break;
            case self::ORDER_DONE:
                $desc = '<text class="text-success">已完成</text>';
                break;
            case self::ORDER_REVOKED:
                $desc = '<text class="text-danger">已取消</text>';
                break;
            case self::ORDER_EXPIRED:
                $desc = '<text class="text-warning">已过期</text>';
                break;
        }

        return $desc;
    }

    public static function getAlipayOrderState($value): string
    {
        switch ($value){
            case "WAIT_BUYER_PAY":
                $state = self::ORDER_DOING;
                break;
            case 'TRADE_CLOSED' :
                $state = self::ORDER_REVOKED;
                break;
            case 'TRADE_SUCCESS':
                $state = self::ORDER_DONE;
                break;
            case 'TRADE_FINISHED':
                $state = self::ORDER_EXPIRED;
                break;
        }

        return $state;
    }
}

